package com.itheima.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.mapper.GroupItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;
    @Autowired
    private GroupItemMapper GroupItemMapper;

    /**
     * 新增检查项
     * @param checkItem
     */
    public void add(CheckItem checkItem) {

        checkItemMapper.insert(checkItem);

    }

    /**
     * 根据id删除检查项
     * @param id
     */
    public void delete(Integer id) {

        checkItemMapper.deleteById(id);

    }

    /**
     * 根据检查组合id查询检查项
     * @param checkgroupId
     * @return
     */
    public ArrayList<Integer> findCheckItemIdsByCheckGroupId(Integer checkgroupId) {

        ArrayList<Integer> checkItemIds = GroupItemMapper.findCheckItemIdsByCheckGroupId(checkgroupId);

        return checkItemIds;
    }

    /**
     * 编辑检查项
     * @param checkItem
     */
    public void edit(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<CheckItem> page = checkItemMapper.pageQuery(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 查询所有检查项
     * @return
     */
    public ArrayList<CheckItem> findAll() {

        ArrayList<CheckItem> checkItems = checkItemMapper.findAll();

        return checkItems;
    }

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    public CheckItem findById(Integer id) {
        CheckItem checkItem = checkItemMapper.findById(id);
        return checkItem;
    }
}
